```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Fork/Join框架深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            overflow-x: auto;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(118, 75, 162, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover:after {
            height: 100%;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="inline-block px-3 py-1 bg-white bg-opacity-20 rounded-full mb-6">
                <span class="text-sm font-semibold">JAVA并行编程</span>
            </div>
            <h1 class="text-4xl md:text-6xl font-bold mb-6 leading-tight">
                Fork/Join框架
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto mb-10">
                高效并行，分而治之 - 深入解析Java多核处理器并行计算框架
            </p>
            <div class="flex justify-center space-x-4">
                <a href="#overview" class="px-6 py-3 bg-white text-indigo-700 rounded-lg font-medium hover:bg-opacity-90 transition duration-300">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 md:px-0 py-16">
        <!-- Overview Section -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-600 mr-4"></div>
                <h2 class="text-3xl font-bold">Fork/Join框架概述</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                    <div class="text-indigo-600 mb-4">
                        <i class="fas fa-project-diagram text-4xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">分治法原理</h3>
                    <p class="text-gray-700">
                        Fork/Join框架是一种基于分治法(Divide and Conquer)的并行计算框架。通过将大任务分解为小任务并并行执行，大幅提升计算效率。框架提供了任务分解和结果合并的高效机制，并对线程池管理进行了优化。
                    </p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-8 card-hover">
                    <div class="text-purple-600 mb-4">
                        <i class="fas fa-cogs text-4xl"></i>
                    </div>
                    <h3 class="text-xl font-bold mb-3">核心组件</h3>
                    <ul class="list-disc pl-5 text-gray-700 space-y-2">
                        <li><span class="font-semibold">ForkJoinPool</span>：管理工作线程池，协调任务调度</li>
                        <li><span class="font-semibold">RecursiveTask</span>：返回结果的可分解任务</li>
                        <li><span class="font-semibold">RecursiveAction</span>：无返回值的可分解任务</li>
                    </ul>
                </div>
            </div>

            <div class="mermaid mb-12">
                flowchart TD
                    A[大任务] --> B{是否足够小?}
                    B -->|是| C[直接执行任务]
                    B -->|否| D[分解为子任务]
                    D --> E[Fork子任务1]
                    D --> F[Fork子任务2]
                    E --> G[递归处理]
                    F --> H[递归处理]
                    G --> I[合并结果]
                    H --> I
                    I --> J[返回最终结果]
            </div>

            <div class="prose max-w-none">
                <p class="text-lg text-gray-700">
                    Fork/Join框架通过递归分解任务和并行处理任务，能够显著提升任务执行的效率。它特别适合处理可以递归分解的算法，如排序、搜索和数学计算等场景。
                </p>
            </div>
        </section>

        <!-- ForkJoinPool Section -->
        <section id="forkjoinpool" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-600 mr-4"></div>
                <h2 class="text-3xl font-bold">ForkJoinPool的实现</h2>
            </div>
            
            <div class="prose max-w-none mb-10">
                <p class="text-lg text-gray-700">
                    <span class="highlight font-semibold">ForkJoinPool</span>是框架的核心类，负责管理线程池、任务调度和工作窃取。它实现了高效的并行任务执行机制，避免了线程频繁创建和销毁的开销。
                </p>
            </div>

            <div class="mb-10">
                <h3 class="text-2xl font-bold mb-4 text-gray-800">核心代码实现</h3>
                <div class="code-block p-6 mb-6">
                    <pre><code class="language-java">
public class ForkJoinPool extends AbstractExecutorService {
    private static final int MAX_CAPACITY = 0x7fff0000;  // 最大线程池容量
    private final WorkQueue[] workQueues;
    private final ForkJoinWorkerThreadFactory factory;
    private final int parallelism;

    public ForkJoinPool(int parallelism) {
        this.parallelism = parallelism;
        this.workQueues = new WorkQueue[parallelism];
        this.factory = new DefaultWorkerThreadFactory();  // 默认工厂
    }

    public void submit(ForkJoinTask<?> task) {
        // 提交任务
        if (task != null) {
            task.fork();  // 启动任务
        }
    }

    public ForkJoinTask<?> invokeAll(Collection<? extends ForkJoinTask<?>> tasks) {
        // 提交一组任务
        ForkJoinTask<?>[] arr = tasks.toArray(new ForkJoinTask[tasks.size()]);
        for (ForkJoinTask<?> task : arr) {
            task.fork();  // 启动任务
        }
        return arr[0];
    }

    public void execute(ForkJoinTask<?> task) {
        // 执行任务
        if (task != null) {
            task.fork();
        }
    }
}
                    </code></pre>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">执行流程</h3>
                    <ul class="space-y-4 text-gray-700">
                        <li class="flex items-start">
                            <div class="bg-indigo-100 text-indigo-600 rounded-full p-2 mr-3">
                                <i class="fas fa-play text-sm"></i>
                            </div>
                            <div>
                                <span class="font-semibold">submit()</span>：将任务提交给线程池并立即执行
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-indigo-100 text-indigo-600 rounded-full p-2 mr-3">
                                <i class="fas fa-tasks text-sm"></i>
                            </div>
                            <div>
                                <span class="font-semibold">invokeAll()</span>：提交一组任务并并行执行
                            </div>
                        </li>
                        <li class="flex items-start">
                            <div class="bg-indigo-100 text-indigo-600 rounded-full p-2 mr-3">
                                <i class="fas fa-random text-sm"></i>
                            </div>
                            <div>
                                <span class="font-semibold">工作窃取算法</span>：线程从其他队列偷取任务提高并发效率
                            </div>
                        </li>
                    </ul>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">关键特性</h3>
                    <div class="bg-white rounded-lg border border-gray-200 p-6">
                        <ul class="space-y-3">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>自动任务分解与调度</div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>高效的线程池管理</div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>工作窃取(Work Stealing)算法</div>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <div>适合处理递归型任务</div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- ForkJoinTask Section -->
        <section id="forkjointask" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-600 mr-4"></div>
                <h2 class="text-3xl font-bold">ForkJoinTask的实现</h2>
            </div>
            
            <div class="prose max-w-none mb-10">
                <p class="text-lg text-gray-700">
                    <span class="highlight font-semibold">ForkJoinTask</span>是任务抽象基类，它定义了任务分解和执行的基本框架。其两个主要子类<code>RecursiveTask</code>和<code>RecursiveAction</code>分别处理有返回结果和无返回结果的任务。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">RecursiveTask (有返回值)</h3>
                    <div class="code-block p-6">
                        <pre><code class="language-java">
public abstract class RecursiveTask<V> extends ForkJoinTask<V> {
    public final V fork() {
        return super.fork();
    }

    public V compute() {
        // 具体任务的计算逻辑
        return null;
    }

    @Override
    public final boolean exec() {
        V result = compute();
        setRawResult(result);
        return true;
    }
}
                        </code></pre>
                    </div>
                    <div class="mt-4 text-gray-700">
                        <p><span class="font-semibold">适用场景：</span>需要返回计算结果的任务，如数值计算、搜索等</p>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">RecursiveAction (无返回值)</h3>
                    <div class="code-block p-6">
                        <pre><code class="language-java">
public abstract class RecursiveAction extends ForkJoinTask<Void> {
    public final void fork() {
        super.fork();
    }

    public void compute() {
        // 具体任务的计算逻辑
    }

    @Override
    public final boolean exec() {
        compute();
        setRawResult(null);
        return true;
    }
}
                        </code></pre>
                    </div>
                    <div class="mt-4 text-gray-700">
                        <p><span class="font-semibold">适用场景：</span>不需要返回结果的操作，如数据转换、批量处理等</p>
                    </div>
                </div>
            </div>

            <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-lg mb-10">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-info-circle text-blue-500 text-2xl mt-1 mr-3"></i>
                    </div>
                    <div>
                        <h3 class="text-lg font-bold text-gray-800 mb-2">关键区别</h3>
                        <p class="text-gray-700">
                            <span class="font-semibold">RecursiveTask</span>用于需要返回结果的计算任务，而<span class="font-semibold">RecursiveAction</span>用于执行没有返回值的操作。两者都实现了任务分解和执行的基本逻辑，但处理结果的方式不同。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Execution Flow Section -->
        <section id="execution" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-600 mr-4"></div>
                <h2 class="text-3xl font-bold">任务拆分与合并的执行流程</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">执行流程图解</h3>
                    <div class="mermaid">
                        flowchart LR
                            A[开始] --> B[分解任务]
                            B --> C[子任务1]
                            B --> D[子任务2]
                            C --> E[继续分解?]
                            D --> F[继续分解?]
                            E -->|是| G[递归分解子任务1]
                            F -->|是| H[递归分解子任务2]
                            E -->|否| I[执行子任务1]
                            F -->|否| J[执行子任务2]
                            I --> K[合并结果]
                            J --> K
                            G --> K
                            H --> K
                            K --> L[返回最终结果]
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">关键执行步骤</h3>
                    <ol class="space-y-4 text-gray-700">
                        <li class="flex">
                            <div class="bg-purple-100 text-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0 mr-3">
                                1
                            </div>
                            <div>
                                <span class="font-semibold">任务分解</span>：将大任务递归分解为足够小的子任务
                            </div>
                        </li>
                        <li class="flex">
                            <div class="bg-purple-100 text-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0 mr-3">
                                2
                            </div>
                            <div>
                                <span class="font-semibold">并行执行</span>：子任务由不同线程并行执行
                            </div>
                        </li>
                        <li class="flex">
                            <div class="bg-purple-100 text-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0 mr-3">
                                3
                            </div>
                            <div>
                                <span class="font-semibold">结果合并</span>：将子任务结果递归合并为最终结果
                            </div>
                        </li>
                        <li class="flex">
                            <div class="bg-purple-100 text-purple-600 rounded-full w-8 h-8 flex items-center justify-center flex-shrink-0 mr-3">
                                4
                            </div>
                            <div>
                                <span class="font-semibold">工作窃取</span>：空闲线程从其他队列"窃取"任务执行
                            </div>
                        </li>
                    </ol>
                </div>
            </div>
        </section>

        <!-- Work Stealing Section -->
        <section id="workstealing" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-2 h-12 bg-indigo-600 mr-4"></div>
                <h2 class="text-3xl font-bold">WorkQueue与工作窃取</h2>
            </div>
            
            <div class="prose max-w-none mb-10">
                <p class="text-lg text-gray-700">
                    工作窃取算法是Fork/Join框架高效运行的关键。每个工作线程维护一个双端队列(WorkQueue)，线程从队列头部获取任务执行。当自己的队列为空时，线程会从其他线程的队列尾部"窃取"任务执行，从而平衡负载。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">WorkQueue核心实现</h3>
                    <div class="code-block p-6">
                        <pre><code class="language-java">
private static final class WorkQueue {
    private final ForkJoinTask<?>[] tasks;
    private int base;  // 当前任务队列的起始位置
    private int top;   // 当前任务队列的末尾

    public void push(ForkJoinTask<?> task) {
        tasks[top++] = task;  // 将任务推入队列
    }

    public ForkJoinTask<?> pop() {
        return tasks[base++];  // 从队列弹出任务
    }

    public ForkJoinTask<?> steal() {
        // 从其他线程的队列中窃取任务
        return tasks[top--];  // 返回任务
    }
}
                        </code></pre>
                    </div>
                </div>
                <div>
                    <h3 class="text-2xl font-bold mb-4 text-gray-800">工作窃取示意图</h3>
                    <div class="mermaid">
                        flowchart LR
                            Thread1 --> Queue1[任务队列1]
                            Thread2 --> Queue2[任务队列2]
                            Thread3 --> Queue3[任务队列3]
                            Thread4 --> Queue4[任务队列4]
                            
                            Queue1 -->|窃取| Queue4
                            Queue2 -->|窃取| Queue3
                            Queue3 -->|窃取| Queue1
                    </div>
                    <div class="mt-4 text-gray-700">
                        <p>当线程的任务队列为空时，会从其他线程的队列尾部窃取任务执行，避免线程闲置，提高CPU利用率。</p>
                    </div>
                </div>
            </div>

            <div class="bg-indigo-50 rounded-xl p-8">
                <h3 class="text-2xl font-bold mb-4 text-indigo-800">工作窃取的优势</h3>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="text-indigo-600 mb-3">
                            <i class="fas fa-bolt text-2xl"></i>
                        </div>
                        <h4 class="font-bold mb-2">负载均衡</h4>
                        <p class="text-gray-700 text-sm">自动平衡各线程工作量，减少空闲时间</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="text-indigo-600 mb-3">
                            <i class="fas fa-tachometer-alt text-2xl"></i>
                        </div>
                        <h4 class="font-bold mb-2">高吞吐量</h4>
                        <p class="text-gray-700 text-sm">最大化CPU利用率，提高并行效率</p>
                    </div>
                    <div class="bg-white p-6 rounded-lg shadow-sm">
                        <div class="text-indigo-600 mb-3">
                            <i class="fas fa-random text-2xl"></i>
                        </div>
                        <h4 class="font-bold mb-2">低争用</h4>
                        <p class="text-gray-700 text-sm">减少线程间竞争，降低同步开销</p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-bold">技术小馆</h3>
                    <p class="text-gray-400 mt-1">深入探索Java技术细节</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300">
                        <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```